package com.yuanqi.repository;

import com.yuanqi.domain.AccountsPayable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface AccountsPayableRepository extends JpaRepository<AccountsPayable, Long> {
    
    List<AccountsPayable> findBySupplierId(Long supplierId);
    
    List<AccountsPayable> findByOverdueStatus(Integer overdueStatus);
    
    @Query("SELECT SUM(ap.payableAmount) FROM AccountsPayable ap WHERE ap.overdueStatus = 1")
    Double getTotalOverdueAmount();
    
    @Query("SELECT SUM(ap.unpaidAmount) FROM AccountsPayable ap")
    Double getTotalUnpaidAmount();
    
    List<AccountsPayable> findByDueDateBefore(LocalDate date);
}


